<template>
  <div class="app-container book">
    <div class="content">
      <div class="block" v-for="(item,index) in list" :key="index" @click="goToInfo(item)">
        <div class="item">
          <img class="item-cover" :src="newspaperUrl+item.max_file_name.substr(0,4)+'.jpg'" alt="">
          <span class="name">{{item.paper_name}}</span>
          <span class="time">{{item.max_file_name.substr(4,8)}}期</span>
        </div>
      </div>
    </div>
    <div class="pagination">
      <el-pagination @current-change="handleCurrentChange" :current-page.sync="currentPage" :page-size="20" layout="total, prev, pager, next, jumper" :total="total">
      </el-pagination>
    </div>
  </div>
</template>

<script>
import { getNewspaperList } from "@/api/index";
import baseUrl from "@/api/base";
export default {
  data() {
    return {
      currentPage: 1,
      list: [],
      total: 0
    };
  },
  components: {},
  created() {
    this.newspaperUrl = baseUrl.newspaperUrl;
    this.getNewspaperList();
  },
  methods: {
    goToInfo(item) {
      this.$router.push("/newspaper/info?max_file_name="+item.max_file_name.slice(0,4)+"&resourceType=4&value="+item.paper_name);
    },
    getNewspaperList(page, pageSize) {
      getNewspaperList(page, pageSize)
        .then(res => {
          console.log(res.data);
          this.total = res.data.total;
          this.list = res.data.data;
        })
        .catch(err => {
          console.log(err);
        });
    },
    handleCurrentChange(val) {
      this.currentPage = val;
      this.getNewspaperList(this.currentPage);
      console.log(`当前页: ${val}`);
    }
  }
};
</script>
<style lang="less" scoped>
.book {
  padding: 0px 20px 20px 20px;
  border-radius: 10px;
  background: #fff;
  .content {
    display: flex;
    flex-wrap: wrap;
    width: 100%;
    border-bottom: 1px solid #eaeaea;
    margin-bottom: 30px;
    .block {
      width: 226px;
      margin-top: 20px;
      padding-bottom: 24px;
      border-bottom: 1px solid #eaeaea;
      margin-bottom: -1px;
      cursor: pointer;
      .item {
        display: flex;
        flex-direction: column;
        .item-cover {
          width: 226px;
          height: 86px;
          border-radius: 10px;
          box-shadow: 0 2px 10px rgba(0,0,0,0.4);
        }
        .name {
          font-size: 18px;
          margin-top: 10px;
        }
        .time {
          font-size: 14px;
          color: #a1a1a1;
          margin-top: 5px;
        }
      }
    }
    .block:not(:nth-child(4n + 1)) {
      padding-left: 85px;
    }
  }
}
</style>


